import { UserFormData } from "./user-form";
import { ProductFormData } from "./product-form";
import { SpecFormData } from "./spec-form";
import { FileFormData } from "./file-form";

import type { IFormData } from "./types";

type FormType = "user" | "product" | "spec"|"file";

export class FormFactory {
  static create(type: FormType): IFormData {
    switch (type) {
      case "user":
        return new UserFormData();
      case "product":
        return new ProductFormData();
      case "spec":
        return new SpecFormData();
      case "file":
        return new FileFormData();

      default:
        throw new Error(`未知的表单类型: ${type}`);
    }
  }

  static createFromExisting(type: FormType, data: any): IFormData {
    const form = this.create(type);
    Object.assign(form, data);
    return form;
  }
}
